package com.djk.controller;

import com.djk.mapper.SysScheduleMapper;
import com.djk.pojo.Result;
import com.djk.pojo.SysSchedule;
import com.djk.service.SysScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/schedule")
public class SysScheduleController {
    @Autowired
    private SysScheduleService scheduleService;

    /**
     * 按照用户id查询所有的日程信息
     * 请求参数：查询字符串
     *
     * @return
     */
    @RequestMapping("/findAllSchedule")
    public Result findAllSchedule(Integer uid) {
        List<SysSchedule> scheduleList = scheduleService.findAllSchedule(uid);
        Result result = Result.ok(scheduleList);
        return result;
    }

    /**
     * 添加一项日程记录
     * 请求参数：json
     */
    @RequestMapping("/addSchedule")
    public Result addSchedule(@RequestBody SysSchedule schedule) {
        scheduleService.addSchedule(schedule);
        return Result.ok(null);
    }

    /**
     * 更新一条日程信息
     * 请求参数：json
     */
    @RequestMapping("/updateSchedule")
    public Result updateSchedule(@RequestBody SysSchedule schedule) {
        scheduleService.updateSchedule(schedule);
        return Result.ok(null);
    }

    /**
     * 删除一条日程信息
     * 请求参数：查询字符串
     */
    @RequestMapping("/deleteSchedule")
    public Result deleteSchedule(Integer sid){
        scheduleService.deleteSchedule(sid);
        return Result.ok(null);
    }

}
